﻿using System;
using BusinessFramework.AOP;

namespace BusinessFramework.Samples.SL
{
    public enum ProductType
    {
        Product,
        Service
    }

    [NotifyPropertyChanged]
    public class Product
    {
        public string Name { get; set; }
        public string Description { get; set; }

        public decimal NetValue { get; set; }
        public decimal GrossValue { get; set; }
        public decimal VatValue { get; set; }

        public ProductType ProductType { get; set; }

        public DateTime DateTime { get; set; }

        private IEntityExtensions _extensions;
        public IEntityExtensions Extensions
        {
            get
            {
                if (_extensions == null)
                    _extensions = EntityExtensions.RegisterObject(this);
                return _extensions;
            }
            set{}
        }

        [RuleInit]
        public void RuleInit()
        {
            var e = Extensions.GetTypeSafe<Product>();
            //e.CreateValidationRule(ex => ex.Number < 10)
            //    .WithOwner(ex => ex.Number)
            //    .Start();

            e.CreateValidationRule(ex => ex.Name, ValidationFactory.Required())
                .WithModeAtStartup(ValidationRuleStartupMode.None)
                .Start();

            e.CreateValidationRule(ex => ex.DateTime > System.DateTime.Now)
                .WithModeAtStartup(ValidationRuleStartupMode.None)
                .Start();
        }
    }
}